/*
 * Created by JFormDesigner on Fri Nov 15 11:26:56 CST 2024
 */

package com.hafu.view.GYS;

import com.hafu.model.GysInfo;
import com.hafu.service.GysInfoService;
import com.hafu.util.StringUtil;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author aa
 */
public class AddGYSFrm extends JFrame {
    private GysInfoService gysInfoService = new GysInfoService();
    public AddGYSFrm() {
        initComponents();
    }

    private void button1(ActionEvent e) {
        // TODO add your code here 添加供应商信息事事件
        String name = textField2.getText();
        String tel = textField3.getText();
        if (StringUtil.isEmpty(name)){
            JOptionPane.showMessageDialog(null,"供应商名称不能为空");
            return;
        }
        if (StringUtil.isEmpty(tel)){
            JOptionPane.showMessageDialog(null,"供应商电话不能为空");
            return;
        }
        GysInfo gysInfo = new GysInfo(name,tel);
        Boolean aBoolean = gysInfoService.addGYSInfo(gysInfo);
        if (aBoolean){
            JOptionPane.showMessageDialog(null,"添加供应商信息成功");
            this.dispose();
        }else {
            JOptionPane.showMessageDialog(null,"添加供应商信息失败");
        }
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        textField2 = new JTextField();
        textField3 = new JTextField();
        label1 = new JLabel();
        label2 = new JLabel();
        button1 = new JButton();

        //======== this ========
        setTitle("\u6dfb\u52a0\u4f9b\u5e94\u5546");
        Container contentPane = getContentPane();

        //---- label1 ----
        label1.setText("\u4f9b\u5e94\u5546\u540d\u5b57");

        //---- label2 ----
        label2.setText("\u4f9b\u5e94\u5546\u7535\u8bdd");

        //---- button1 ----
        button1.setText("\u63d0\u4ea4");
        button1.addActionListener(e -> button1(e));

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(30, 30, 30)
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addComponent(label1, GroupLayout.PREFERRED_SIZE, 95, GroupLayout.PREFERRED_SIZE)
                        .addComponent(label2))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 144, Short.MAX_VALUE)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                        .addComponent(textField2, GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
                        .addComponent(textField3, GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
                    .addGap(114, 114, 114))
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(137, 137, 137)
                    .addComponent(button1)
                    .addContainerGap(283, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(72, 72, 72)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                        .addComponent(textField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(label1))
                    .addGap(41, 41, 41)
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addComponent(textField3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(label2))
                    .addGap(21, 21, 21)
                    .addComponent(button1)
                    .addContainerGap(66, Short.MAX_VALUE))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JTextField textField2;
    private JTextField textField3;
    private JLabel label1;
    private JLabel label2;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
